
//引入网络库
import { get, post } from "../../util/util.js"
// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称
   */
  name: "sendMoney",
  /**
   * 页面的初始数据
   */

  data: { 
    uid: '', 
    count: '', 
    idno: '', 
    realname: '', 
    realAuth: '',
    nowBalance:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },
  onLoad: function (o) {//user/ModifyUserinfo
    var that = this;
    that.setData({
      uid: o.uid,
      realAuth: o.realAuth,
    })
    post("/user/mywallet", { uid: that.data.uid }).then(data => {
      // nowBalance
      var result = data.data.balance/100;
      var nb = parseInt(result)*100;

      that.setData({
        nowBalance: nb, 
      })
    })
    console.log("realAuth=====" + that.data.realAuth)
  },
  /** 
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this;
    wx.getStorage({
      key: 'login',
      success: function (res) {
        var data = res.data
        console.log("realAuth====" + data.data.realAuth);
        that.setData({
          uid: data.data.uid,
          realAuth: String(data.data.realAuth),
        });
      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  //input监听
  realNameJzInput:function(e){
    this.setData({
      realname: e.detail.value
    })
  },
  numberJzInput: function (e) {
    this.setData({
      idno: e.detail.value
    })
  },
  moneyInput: function (e) {
    this.setData({
      count: e.detail.value
    })
  },
 

  //以下为自定义点击事件
  applyMoney: function (e) {
    var that = this;
    var param = {};
    var resultMoney = that.data.count / 100;
    var resultCount = parseInt(resultMoney)*100;
    wx.showModal({
      title: '提示',
      content: '您当前申请提现积分计算结果为：' + resultCount+'积分',
      success: function (res) {
        if (res.confirm) {//用户点击确定
          if (that.data.realAuth == 'true') {
            console.log("realAuth===true==进入===")
            param.uid = that.data.uid;
            param.count = resultCount;
          } else {
            console.log("realAuth===false==进入===")
            param.uid = that.data.uid;
            param.count = resultCount;
            param.idno = that.data.idno;
            param.realname = that.data.realname;
          }
          post("/user/applyMoney", param).then(data => {
            console.log("提现================" + JSON.stringify(data))
            if (data.code == 0) {
              wx.showModal({
                title: '提示',
                content: data.msg,
                success: function (res) {
                  if (res.confirm) {
                    console.log('用户点击确定')
                    wx.navigateBack({
                      delta: -1
                    });
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                }
              })
            } else {
              wx.showModal({
                title: '提示',
                content: data.msg,
                success: function (res) {
                  if (res.confirm) {
                    console.log('用户点击确定')
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                }
              })
            }
          })
         
        } else if (res.cancel) {//用户点击取消
      
        }
      }
    })
  }

})

